import axios from './init'
import qs from 'qs'

export const getCategories = async (param:{
  type?: number,
  pagenum?: number,
  pagesize?: number
}) => {
  const { data } = await axios.get('categories?' + qs.stringify({
    type: param.type,
    pagenum: param.pagenum,
    pagesize: param.pagesize
  }))
  return data
}

export const editCategories = async (param:{id:number, name:string}) => {
  const { data } = await axios.put(`categories/${param.id}`, { cat_name: param.name })
  return data
}
export const deleteCategories = async (id:number) => {
  const { data } = await axios.delete(`categories/${id}`)
  return data
}
export const addCategories = async (param:{pid:number, name:string, level:number}) => {
  const { data } = await axios.post('categories', {
    cat_pid: param.pid,
    cat_name: param.name,
    cat_level: param.level
  })
  return data
}
